package com.lvyq.myplayer.ui.activity.history

import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.lvyq.myplayer.R
import com.lvyq.myplayer.base.BaseActivity
import com.lvyq.myplayer.common.util.MockDataUtil
import com.lvyq.myplayer.ui.fragment.history.SongAlbumPagerFragment
import com.lvyq.myplayer.ui.fragment.history.SongPlayLstPagerFragment
import com.lvyq.myplayer.ui.fragment.history.SongPlayPagerFragment
import com.lvyq.myplayer.util.ToolBarManager

/**
 * 文件描述：UserCenterActivity
 * 作者：lvyq
 * 创建时间：2025-06-18
 * 修改时间：2025-06-18
 */
class PlayHistoryActivity : BaseActivity(),ToolBarManager{
    override val toolbar by lazy { findViewById<Toolbar>(R.id.toolBar) }

    private lateinit var historyRecView:ViewPager2

    private lateinit var playHistoryTypeTab:TabLayout

    var playTypeList= MockDataUtil.playTypeList()
    override fun getLayoutId(): Int {
        return  R.layout.activity_play_history
    }

    override fun initData() {
        historyRecView = findViewById(R.id.rvHistoryView)
        playHistoryTypeTab=findViewById(R.id.playHistoryTypeTab)

        //viewPage 绑定
        historyRecView.adapter=object :FragmentStateAdapter(this){
            override fun getItemCount(): Int {
                return playTypeList.size
            }

            override fun createFragment(position: Int): Fragment {
                //单曲
                if (position==0){
                    return SongPlayPagerFragment()
                }
                //歌单
                if (position==1){
                    return SongPlayLstPagerFragment()
                }
                //专辑
                if (position==2){
                    return SongAlbumPagerFragment()
                }
                return SongPlayPagerFragment()
            }

        }
        // 关联 TabLayout 和 ViewPager2
        TabLayoutMediator(playHistoryTypeTab, historyRecView) { tab, position ->
            tab.text = playTypeList[position].name.toString()
        }.attach()
        // 默认选中第一个页面
        historyRecView.setCurrentItem(0, true)
    }

    override fun initListener() {
        super.initListener()
        initSettingToolBar("最近播放")
        enableBackButton()
        }

}






